/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @fileOverview 支付平台1.0
 * 兴趣点轨迹下载业务逻辑
 * @author fengbj
 * @ date 2010-3-8 17:10:11
 */
if (!window.mapbar) {
	window.mapbar = {};
}
if (!window.mapbar.pay) {
	window.mapbar.pay = {};
}
if (!window.mapbar.pay.activationcode) {
	window.mapbar.pay.activationcode = {};
}

(function(_this){
    $.extend(_this , {
        deviceIdCheck : function(){
            var deviceId = $("#deviceId").val();
            if($.trim(deviceId) == ""){
                _this.showError("deviceId" , "设备码不能为空！");
                return false;
            }else if(/[0o]/i.test($.trim(deviceId)) || !/[0-9a-zA-Z]{16}/.test($.trim(deviceId)) ){

                _this.showError("deviceId" , "设备码错误！");
                return false;
            }
            else{
                
                _this.showCom("deviceId" , "验证成功");
                return true;
            }

        },
        deviceIdTwoCheck : function(){
            var deviceIdTwo = $("#deviceIdTwo").val();
            var deviceId = $("#deviceId").val();
            if($.trim(deviceIdTwo) == ""){
                _this.showError("deviceIdTwo" ,"设备码不能为空！");
                return false;
            }else if($.trim(deviceIdTwo) != $.trim(deviceId)){
                _this.showError("deviceIdTwo" ,"两次输入设备码不一致！");
                return false;
            }else{
                
                _this.showCom("deviceIdTwo" , "验证成功");
                return true;
            }

        },
        serialCheck : function(){
            var serial = $("input[name='serial']");
            var s = "";
            serial.each(function(i , n){
                s += n.value;
            })
            if($.trim(s) == ""){
                _this.showError("serial" , "序列号不能为空！");
                return false;
            }else if(!/[0-9a-zA-Z]{16}/.test($.trim(s))){
                _this.showError("serial" , "序列号错误！");
                return false;
            }else{
                
                _this.showCom("serial" , "验证成功");
                return true;
            }
        },
        check : function(){

            if(_this.deviceIdCheck() &&
               _this.deviceIdTwoCheck()&&
               _this.serialCheck()
                ){
                        //alert('提交')
                        return true;

                }else{
                    return false;
                }
            
        },
        showError : function(targetId , content){
            //alert(content);
            $("#" + targetId + "Info").removeClass();
            $("#" + targetId + "Info").addClass("saylistred").html(content);
            $("#" + targetId).focus();

        },
        showInfo : function(targetId , content){
            //alert(content);
            $("#" + targetId + "Info").removeClass();
            $("#" + targetId + "Info").addClass("saylistnomal").html(content);

        },
        showCom : function(targetId , content){
            $("#" + targetId + "Info").removeClass();
            $("#" + targetId + "Info").addClass("saylist").html("");
            //$("#" + targetId).focus();

        },
        move : function(){
            var obj = $(this);
            var s = $.trim(obj.val());
            if(s.length <= 0){
                    if(obj.prev().is("input"))
                        obj.prev().focus();

                
            }else if(s.length >= 4){
                    if(obj.next().is("input"))
                        obj.next().focus();

                
            }
            _this.serialCheck();
        },
        normalSerialCheck : function(){

            var serial = $("input[name='serial']");
            var s = "";
            serial.each(function(i , n){
                s += n.value;
            })
            s = $.trim(s);
            if(s == null || s == ""){
                alert("序列号不能为空！");
                return false;
            }else if(/[0-9A-Za-z]{16}/i.test(s)){
                
                return true;
            }else{
                alert("序列号不正确！");
                return false;
            }
        },
        normalDeviceIdCheck : function(){
            var deviceId = $("#deviceId").val();
            if(deviceId == null || $.trim(deviceId) == ""){
               alert( "设备码不能为空！");
               $("#deviceId").focus();
                return false;
            }else if(/[0o]/i.test($.trim(deviceId)) || !/[0-9a-zA-Z]{16}/.test($.trim(deviceId)) ){
                alert("设备码错误！");
                $("#deviceId").focus();
                return false;
            }
            else{
                return true;
            }
            
        }
    });
})(mapbar.pay.activationcode);